﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace nyxwin.Common.Silverlight.Commands
{
    public class Command : ICommand
    {
        public Command(Action<object> execute)
        {
            this.execute = execute;
            this.canExecute = null;
        }

        public Command(Action<object> execute, Func<object, bool> canExecute)
        {
            this.execute = execute;
            this.canExecute = canExecute;
        }

        public void RaiseCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
                CanExecuteChanged(this, new EventArgs());
        }

        #region ICommand Members

        public bool CanExecute(object parameter)
        {
            if (canExecute == null)
                return true;
            else
                return canExecute(parameter);
        }

        public event EventHandler CanExecuteChanged;
        private Action<object> execute;
        private Func<object, bool> canExecute;

        public void Execute(object parameter)
        {
            execute(parameter);
        }

        #endregion
    }
}
